import {
    reqAddressList,
    reqDeleteUser
} from "../../api/index"
Page({
    data: {
        // 地址列表
        addressArr: []
    },
    // 每次页面出现的时候都获取一次列表数据
    onShow() {
        // 获取地址列表
        this.getAddressLis()
    },
    async getAddressLis() {
        const result = await reqAddressList()
        if (result.code == 200) {
            this.setData({
                addressArr: result.data
            })
        }
    },
    // 点击编辑图标进行页面跳转
    edit(event) {
        const addressId = event.currentTarget.dataset.addressid
        wx.navigateTo({
            url: `/pages/addAddress/addAddress?addressId=${addressId}`,
        })
    },
    // 删除已有的用户信息
    async delete(event) {
        const result = await reqDeleteUser(event.currentTarget.dataset.addressid)
        if (result.code == 200) {
            // 更新数据
            this.getAddressLis()
        } else {
            console.log(result);
        }
    },
})